<template>
	<view>
		<!--header-->
		<view class="s-mybg-box">
			<view class="s-header-center" @tap="login">
				<image :src="user_info.avatar_url?user_info.avatar_url:'/static/images/user@default.png'" class="s-avatar"></image>
				<view class="s-info">
					<view class="s-nickname">{{user_info.nick_name?user_info.nick_name:'未登录'}}</view>
					<view class="s-explain">{{user_info.phone?user_info.phone:'未绑定手机号'}}</view>
				</view>
			</view>
			<view class="s-header-btm">
				<view class="s-btm-item" @tap="collection">
					<view class="s-btm-num">{{user_info.collection_count}}</view>
					<view class="s-btm-text">收藏商品</view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<view class="s-btm-item" @tap="my_live_list">
					<view class="s-btm-num">{{user_info.my_live_count}}</view>
					<view class="s-btm-text">收藏直播</view>
				</view>
				<!-- #endif -->
				<view class="s-btm-item" @tap="footprint">
					<view class="s-btm-num">{{user_info.footprint_count}}</view>
					<view class="s-btm-text">商品足迹</view>
				</view>
			</view>
		</view>
		<view class="s-content-box">
			<view class="s-box s-order-box">
				<s-list-cell :arrow="true" padding="0" :lineLeft="false" @tap="order(0)">
					<view class="s-cell-header">
						<view class="s-cell-title">我的订单</view>
						<view class="s-cell-sub">查看全部订单</view>
					</view>
				</s-list-cell>	
				<view class="s-order-list order-top">
					<view class="s-order-item" @tap="order(1)">
						<view class="s-icon-box">
							<image src="/static/images/icon/icon_daifukuan_3x.png" class="s-order-icon"></image>
							<view class="s-badge s-badge-red" v-if="user_info.order_count1">{{user_info.order_count1>9?'9+':user_info.order_count1}}</view>
						</view>
						<view class="s-order-text">待付款</view>
					</view>
					<view class="s-order-item" @tap="order(2)">
						<view class="s-icon-box">
							<image src="/static/images/icon/icon_daifahuo_3x.png" class="s-order-icon"></image>
							<view class="s-badge s-badge-red" v-if="user_info.order_count2">{{user_info.order_count2>9?'9+':user_info.order_count2}}</view>
						</view>
						<view class="s-order-text">待发货</view>
					</view>
					<view class="s-order-item" @tap="order(3)">
						<view class="s-icon-box">
							<image src="/static/images/icon/icon_daishouhuo_3x.png" class="s-order-icon"></image>
							<view class="s-badge s-badge-red" v-if="user_info.order_count3">{{user_info.order_count3>9?'9+':user_info.order_count3}}</view>
						</view>
						<view class="s-order-text">待收货</view>
					</view>
					<view class="s-order-item" @tap="order(4)">
						<view class="s-icon-box">
							<image src="/static/images/icon/icon_pingjia_3x.png" class="s-order-icon"></image>
							<view class="s-badge s-badge-red" v-if="user_info.order_count4">{{user_info.order_count4>9?'9+':user_info.order_count4}}</view>
						</view>
						<view class="s-order-text">评价</view>
					</view>
					<view class="s-order-item" @tap="order(5)">
						<view class="s-icon-box">
							<image src="/static/images/icon/icon_skuan_3x.png" class="s-order-icon"></image>
							<view class="s-badge s-badge-red" v-if="user_info.order_count5">{{user_info.order_count5>9?'9+':user_info.order_count5}}</view>
						</view>
						<view class="s-order-text">退款/售后</view>
					</view> 
				</view>
			</view>
		
			<view class="s-box s-tool-box">
				<view class="s-cell-header">
					<view class="s-cell-title">常用工具</view>
				</view>
				<view class="s-order-list s-flex-wrap">
					<button hover-class="none" open-type="contact" session-from="weapp" class="s-tool-item special" >
						<view class="s-icon-box">
							<image src="/static/images/icon/icon_kefu_3x.png" class="s-tool-icon"></image>
						</view>
						<view class="s-tool-text special_view">客服服务</view>
					</button>
					<view class="s-tool-item" @tap="address">
						<view class="s-icon-box">
							<image src="/static/images/icon/address.png" class="s-tool-icon"></image>
						</view>
						<view class="s-tool-text">地址管理</view>
					</view>
					<view class="s-tool-item" @tap="about_us">
						<view class="s-icon-box">
							<image src="/static/images/icon/about_us.png" class="s-tool-icon"></image>
						</view>
						<view class="s-tool-text">关于我们</view>
					</view>
					<view class="s-tool-item" @tap="phone">
						<view class="s-icon-box">
							<image src="/static/images/icon/extend/icon_phone.png" class="s-tool-icon"></image>
						</view>
						<view class="s-tool-text">手机归属地</view>
					</view>
					<view class="s-tool-item" @tap="idcard">
						<view class="s-icon-box">
							<image src="/static/images/icon/extend/icon_idcard.png" class="s-tool-icon"></image>
						</view>
						<view class="s-tool-text">身份证查询</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default { 
		data() {
			return {
				user_info:{} //我的信息
			}
		},
		async onShow() {
			await this._onLoad()
		},
		
		methods: {
			async _onLoad(){
				this.user_info =  await this.$s.model.user.my()
				await this.$s.model.cart.getCartSum()
			},
			//订单管理
			async order(status){
				if(this.user_info.user_status){
					return await this.$s.uniApi.navigateTo({url:'../order/order?status='+status})
				}else{
					return await this.$s.uniApi.navigateTo({url:'../login/login'})
				}
			},
			//地址管理
			async address(){
				if(this.user_info.user_status){
					return await this.$s.uniApi.navigateTo({url:'../address/address'})
				}else{
					return await this.$s.uniApi.navigateTo({url:'../login/login'})
				}
			},
			// 关于我们
			async about_us(){
				return await this.$s.uniApi.navigateTo({url:'../about_us/about_us'})
			},
			async phone(){
				return await this.$s.uniApi.navigateTo({url:'../extend/phone/phone'})
			},
			async idcard(){
				return await this.$s.uniApi.navigateTo({url:'../extend/idcard/idcard'})
			},
			//商品足迹
			async footprint(){
				if(this.user_info.user_status){
					return await this.$s.uniApi.navigateTo({url:'../footprint/footprint'})
				}else{
					return await this.$s.uniApi.navigateTo({url:'../login/login'})
				}
			},
			//收藏直播
			async my_live_list(){
				if(this.user_info.user_status){
					return await this.$s.uniApi.navigateTo({url:'../my_live_list/my_live_list'})
				}else{
					return await this.$s.uniApi.navigateTo({url:'../login/login'})
				}
			},
			
			// 收藏商品
			async collection(){
				if(this.user_info.user_status){
					return await this.$s.uniApi.navigateTo({url:'../collection/collection'})
				}else{
					return await this.$s.uniApi.navigateTo({url:'../login/login'})
				}
			},
			//跳转登录页
			async login(){
				if(this.user_info.user_status){
					return await this.$s.uniApi.navigateTo({url:'../set/set'})
				}else{
					return await this.$s.uniApi.navigateTo({url:'../login/login'})
				}
			}
		},
		//下拉刷新
		async onPullDownRefresh() {
		   await this._onLoad()
		   uni.stopPullDownRefresh()
		}
	} 
</script>
<style lang="scss" scoped>
@import 'my.scss';
</style>